home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
PET
/
S-Super PET
/
(s)t4.d64
/
QUICKSORT.BAS
< prev
next >
Wrap
BASIC Source File
|
2009-01-18
|
1KB
|
48 lines
10 input "enter number of item to be sorted ? ",x
20 dim integer(x)
30 for i=1 to x
40 integer(i)=int(rnd*1000)+1
50 next i
60 print mat integer;
70 rem
80 rem sorting out the string in ascending order
90 rem
100 print"sort start"
110 start=time
120 call sort(1,x,1,x)
130 print"time = ";time-start;" seconds"
140 print mat integer;
150 stop
160
170
180 proc sort(left,right,i,j)
190 i=left
200 j=right
210 if i < j
220 val=integer(i)
230 loop
240 while i < j and val < integer(j)
250 j = j-1
260 endloop
270 integer(i) = integer(j)
280 i=i+1
290 while i < j and integer(i) < val
300 i = i+1
310 endloop
320 integer(j) = integer(i)
330 if i>=j then quit
340 j=j-1
350 endloop
360 integer(j)=val
370 i=j-1
380 j=j+1
390 if right-j <= i-left
400 call sort(j,right,j,right)
410 call sort(left,i,left,i)
420 else
430 call sort(left,i,left,i)
440 call sort(j,right,j,right)
450 endif
460 endif
470 endproc